package com.bw.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.bw.domain.SysBrand;
import com.bw.domain.SysGoods;
import com.bw.service.SysBrandService;
import com.bw.service.SysGoodsService;
import com.bw.utils.common.Result;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author bobo棒
 * @date 2024年03月08日 11:21
 */
@RequestMapping("brands")
@RestController
public class BrandsController {
    @Autowired
    SysBrandService sysBrandService;
    @RequestMapping("add")
    public Result add(@RequestBody SysBrand sysBrand) {
        boolean b = sysBrandService.save(sysBrand);
        return b?Result.success():Result.fail();
    }

    @RequestMapping("list")
    public Result list() {
        List<SysBrand> list = sysBrandService.list();
        return Result.success(list);
    }


    @RequestMapping("checkUnique")
    public Result checkUnique(String name) {
        LambdaQueryWrapper<SysBrand> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysBrand::getName, name);

        SysBrand brand = sysBrandService.getOne(queryWrapper);
        return Result.success(brand);
    }

    @RequestMapping("delById")
    public Result delById(Integer id){
        boolean b = sysBrandService.removeById(id);
        return b?Result.success():Result.fail();
    }
}
